<template>
  <div class="home">
    <img src="../../assets/images/inOutIsland.png" />
    <div style="margin-bottom:7rem ;">
    </div>
    <van-cell-group inset>
      <van-form ref="formDataRef" validate-first @submit="onSubmit">
        <van-field style="height: 3rem;" input-align="right" label="身份证号码" required v-model="formData.cardNo"
          name="cardNo" placeholder="请输入身份证号码" :rules="rulesCardNo" />
      </van-form>

      <van-cell style="height: 5rem;">
        <div style="margin: 16px 0rem 3rem 0rem; display: flex">
          <van-button type="primary" native-type="submit" @click="onSubmit()" block>查 询</van-button>
        </div>
      </van-cell>
    </van-cell-group>

  </div>
</template>

<script>
import { Toast, Dialog } from 'vant'
import { queryTrafficInfoByCardNo, getTruckFilingById } from '@/api/truck/record'
export default {

  data() {
    return {
      formData: {
        cardNo: ''
      },
      rulesCardNo: [
        {
          required: true,
          message: '请输入身份证号',
          trigger: ['blur', 'change']
        },
        {
          pattern: /^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]{16}([0-9]|[xX])$/,
          message: '身份证号码格式错误！'
        }
      ]
    }
  },
  mounted() {
  },
  filters: {
    upper: function (value) {
      if (!value) return ''
      value = value.toString()
      return value.toUpperCase()
    }
  },
  methods: {
    toUpperCase(obj) {
      obj.value = obj.value.toUpperCase()
    },
    onSubmit() {
      if (!this.formData.cardNo.trim()) {
      }
      this.$refs.formDataRef.validate().then(() => {
        Toast.loading({
          message: '加载中...',
          forbidClick: true,
          duration: 10000
        })
        queryTrafficInfoByCardNo(this.formData).then((res) => {
          Toast.clear()
          if (res.data.errcode === 0) {
            this.$router.push({
              name: 'truck-filing-info',
              query: { id: res.data.data.id }
            })
            const TIMEOUT = setTimeout(() => {
              Dialog.close()
              clearTimeout(TIMEOUT)
            }, 1000)
          } else {
            Toast.fail("未查到报备信息")
          }
        })
      })
    }
  }
}
</script>
<style lang="less" scoped>
.upload-img-5 {
  margin: 5px 0 90px 0;
}

.upload-img-1 {
  margin: 5px 0 15px 0;
}

.home {
  // background: url('../../assets/images/smtb.jpg') no-repeat;
  background-color: #f5f5f5;
  height: 100%;

  img {
    // background: url('../../assets/images/smtb.jpg');
    width: 100%;
  }

  .dialog-container {
    height: 70vh;
    overflow-y: auto;
  }

  .get-area {
    width: 100%;
    padding: 0 0.8rem;
    font-size: 0.747rem;
    color: #fff;
    background-color: #1989fa;
    border: 0.053rem solid #1989fa;
    height: 2.347rem;
    line-height: 2.347rem;
    text-align: center;
    border-radius: 0.107rem;
    cursor: pointer;
    box-sizing: border-box;
    margin-right: 10px;
  }

  /deep/.van-field__label {
    width: 8em;
  }

  /deep/.van-field__error-message {
    text-align: right;
  }

  .title {
    // font-size: 28px;
    text-indent: 20px;
    padding: 50px 0 20px;
  }

  .container {
    width: 90%;
    height: 80vh;
    overflow-y: auto;
    border: 1px solid #adadad;
    margin: auto;

    .item {
      margin: 10px;
    }
  }
}

.up-and-down {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f1f3f4;
  height: 80px;
  color: #333;
}

.home .blue {
  background-color: transparent;
}

.home .van-cell {
  background-color: transparent;
}
</style>
